package cn.tedu.map;

import org.junit.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;



/*set集合中不可以存放相同数据
* set集合中数据都是无序的
* set集合中可以存放null值，也只允许存放0-1个*/
public class TestSet {
    @Test
    public void test(){

        Set<String> set = new HashSet<String>();
     /*   set.add("牛气冲天");
        set.add("牛气冲天");*/
        set.add("牛气冲天");
        set.add("虎虎生威");
        set.add(null);
        System.out.println(set.size());//3
        System.out.println(set);
        System.out.println(set.contains("小脑斧"));
        System.out.println(set.hashCode());
        System.out.println(set.size());
        System.out.println(set.isEmpty());
        System.out.println(set.equals("虎虎生威"));
        System.out.println(Arrays.toString(set.toArray()));
        System.out.println(set.remove("虎虎生威"));
        //set.clear();
        System.out.println(set);
        Set<String> set1 = new HashSet<>();
        set1.add("小狮子");
        set1.add("小海豚");
        set1.add("小兔纸");
        set1.add("瘪犊子");
        set1.add("小脑虎");
        System.out.println("*****************************************");
        System.out.println(set1);
        System.out.println(set.addAll(set1));
        System.out.println(set);
        System.out.println(set.containsAll(set1));//是否包含
       // System.out.println(set.retainAll(set1));//取交集,公共部分，需要注意的是 谁来调用就影响谁
        System.out.println(set1.retainAll(set));
        System.out.println(set);
        System.out.println(set1);
        Iterator<String> iterator = set.iterator();
        while (iterator.hasNext()){
            System.out.print(iterator.next()+"\t*\t");
        }
        System.out.println();
        for (String s : set) {
            System.out.print(s+"\t*\t");
        }
        System.out.println();
    }

}
